package com.example.demo.service.impl;



import com.example.demo.dao.CourseMatsDao;
import com.example.demo.entity.CourseMatsBean;
import com.example.demo.service.CourseMatsService;
import com.example.demo.util.PageEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseMatsServiceImpl implements CourseMatsService {

    @Autowired
    private CourseMatsDao courseMatsDao;

    @Override
    public List<CourseMatsBean> all() {
        return courseMatsDao.getAll();
    }

    @Override
    public Integer add(CourseMatsBean courseMatsBean) {
        return courseMatsDao.insert(courseMatsBean);
    }


    @Override
    public Integer update(CourseMatsBean courseMatsBean) {
        return courseMatsDao.edit(courseMatsBean);
    }

    @Override
    public Integer delete(Integer id) {
        return courseMatsDao.del(id);
    }

    @Override
    public CourseMatsBean one(Integer id) {
        return courseMatsDao.getOne(id);
    }

    @Override
    public PageEntity list(Integer pageNo, Integer pageSize,String address,String name,String sortOrder) {

        // 根据页码 求 跳过多少条数据
        Integer jump = (pageNo-1)*pageSize;

        Integer count = courseMatsDao.getCount(address, name);
        List<CourseMatsBean> rows = courseMatsDao.getPage(jump, pageSize,  address, name, sortOrder);


        PageEntity<List> listPageEntity = new PageEntity<List>(rows,count);
        return listPageEntity;
    }


}

